package org.ahuanlien.crm.web.controller;

import org.ahuanlien.crm.query.ToBeAuditedBillQueryObbject;
import org.ahuanlien.crm.service.IToBeAuditedBillIService;
import org.ahuanlien.crm.util.JSONResult;
import org.ahuanlien.crm.util.LogicException;
import org.ahuanlien.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("toBeAuditedBill")
public class ToBeAuditedBillController {

    @Autowired
    private IToBeAuditedBillIService toBeAuditedBillIService;


    @RequestMapping("view")
    public String view() {
        return "toBeAuditedBill/view";
    }

    @RequestMapping("query")
    @ResponseBody
    public PageResult query(ToBeAuditedBillQueryObbject qo) {
        PageResult result = toBeAuditedBillIService.query(qo);
        return result;
    }

    @RequestMapping("submitToBeAudited")
    @ResponseBody
    public JSONResult submitToBeAudited(String caseNumber) {
        try {
            toBeAuditedBillIService.submitToBeAudited(caseNumber);
        } catch (LogicException e) {
            e.printStackTrace();
            return JSONResult.mark(e.getMessage());
        }
        return JSONResult.success("提交成功");
    }

    @RequestMapping("audit")
    @ResponseBody
    public JSONResult audit(String caseNumber) {
        try {
            toBeAuditedBillIService.audit(caseNumber);
        } catch (LogicException e) {
            e.printStackTrace();
            return JSONResult.mark(e.getMessage());
        }
        return JSONResult.success("审核成功");
    }

    @RequestMapping("reject")
    @ResponseBody
    public JSONResult reject(String caseNumber) {
        try {
            toBeAuditedBillIService.reject(caseNumber);
        } catch (LogicException e) {
            e.printStackTrace();
            return JSONResult.mark(e.getMessage());
        }
        return JSONResult.success("退回成功");
    }
}
